
import { _decorator, Component, Node } from 'cc';
import { TriggerManager } from './TriggerManager';
import { RenderManager } from '../Base/RenderManager';
import { ItemStatusEnum, ItemTypeEnum, TriggerStatusEnum, TriggerTypeEnum } from '../../Enum';
import DataManager from '../Runtime/DataManager';
const { ccclass, property } = _decorator;



@ccclass('MailBoxTriggerManager')
export class MailBoxTriggerManager extends TriggerManager {
    type = TriggerTypeEnum.MailBox;

    @property(Node)
    closeNode: Node = null;

    @property(Node)
    openNode: Node = null;

    render() {
        super.render();
        const open = DataManager.Instance.mailBoxStatus === TriggerStatusEnum.Resolved
        this.closeNode.active = !open;
        this.openNode.active = open;
    }

    handleTrigger() {
        if (DataManager.Instance.currItemType === ItemTypeEnum.KEY && DataManager.Instance.isSelect) {
            //把当前选项设置为null
            DataManager.Instance.currItemType = null;
            //把选择状态设置为false
            DataManager.Instance.isSelect = false;
            DataManager.Instance.items.find(i => i.type === ItemTypeEnum.KEY).status = ItemStatusEnum.DISABLED;
            DataManager.Instance.items.find(i => i.type === ItemTypeEnum.MAIL).status = ItemStatusEnum.Scene;
            DataManager.Instance.items = [...DataManager.Instance.items];
            DataManager.Instance.mailBoxStatus = TriggerStatusEnum.Resolved;
        }

    }
}